;; config js2-mode for js files
(setq auto-mode-alist
      (append
       '(
         ("\\.js\\'" . js-mode)
         ;; ("\\.vue\\'" . web-mode)
         ("\\.html\\'" . web-mode)
         )
       auto-mode-alist))

(use-package typescript-mode
  :ensure t)
;; (use-package vue-mode
;;   :ensure t)

(use-package web-mode
  :ensure t
  )

;; config for web mode
(defun my-web-mode-indent-setup ()
  (setq web-mode-markup-indent-offset 2) ; web-mode, html tag in html file
  (setq web-mode-css-indent-offset 2)    ; web-mode, css in html file
  (setq web-mode-code-indent-offset 2)   ; web-mode, js code in html file
  )

(add-hook 'web-mode-hook 'my-web-mode-indent-setup)


(defun my-toggle-web-indent ()
  (interactive)
  ;; web development
  (if (or (eq major-mode 'js-mode) (eq major-mode 'js2-mode))
      (progn
	(setq js-indent-level (if (= js-indent-level 2) 4 2))
	(setq js2-basic-offset (if (= js2-basic-offset 2) 4 2))))

  (if (eq major-mode 'web-mode)
      (progn (setq web-mode-markup-indent-offset (if (= web-mode-markup-indent-offset 2) 4 2))
	     (setq web-mode-css-indent-offset (if (= web-mode-css-indent-offset 2) 4 2))
	     (setq web-mode-code-indent-offset (if (= web-mode-code-indent-offset 2) 4 2))))
  (if (eq major-mode 'css-mode)
      (setq css-indent-offset (if (= css-indent-offset 2) 4 2)))
)


(use-package yaml-mode
  :ensure t
  )

(use-package dtrt-indent
  :ensure t
  :diminish
  :hook (prog-mode . dtrt-indent-mode))


(provide 'init-web)